/**
 *	The NeuroCoSA Toolkit
 *	Copyright (C) 2003-6 Stuart Meikle.
 *
 *	This is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation; either
 *	version 2.1 of the License, or (at your option) any later version.
 *
 *	This library is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *	Lesser General Public License for more details.
 *
 * @author	Stuart Meikle
 * @version	2006-halloween(mk2)
 * @license	LGPL
 */

package org.stumeikle.NeuroCoSA.NIS;
import java.io.*;
import java.util.*;
import org.stumeikle.NeuroCoSA.PubSub.YesterdaysNews;
import org.stumeikle.NeuroCoSA.PubSub.TimeLord;

/** Information types , for storing info in the brain info service.
 *  This one is a kind of publication. Contains a pointer to a wrapped long
 *  updated 20071213 stumeikle.
 */
public	class	InfoDoubleWithSingleStore extends InfoWithSingleStore
{
    class	DoubleObject
    {	double	d;
	DoubleObject(double a) { d=a; }
    }

    public InfoDoubleWithSingleStore(String n, double v, TimeLord t)
    {
	super(n,t);
	
	/* old code as of 20071213
	//need to create 2 double objects , one for current and one for 
	//previous value. these are the containers
	iValue = (Object) new DoubleObject(v);
	iPreviousValue = (Object) new DoubleObject(0.0);
	*/
	
	setValue( (Object) new DoubleObject(v) );
    }

    public double getDoubleValue()
    {
	DoubleObject 	o = (DoubleObject)getValue();
	return o.d;
    }

    public double getDoubleValue(long t)
    {
	DoubleObject 	o = (DoubleObject)getValue(t);
	return o.d;
    }

    public void	setDoubleValue( double d ) 
    {  
	//EFFICIENCY here could be IMPROVED!!
	DoubleObject	dob = new DoubleObject( d );
	setValue( dob );

	/* --- old code, pre 20071213
	lock(this);

	//choose where to store the d using same logic as yesterdays news
	//little bit tricky
	long	 now = iTimeLord.getTime();

	if (now!=iUpdateTime)
	{
	    ((DoubleObject)iPreviousValue).d = ((DoubleObject)iValue).d;
	}

	((DoubleObject)iValue).d = d;
	iUpdateTime = now;
	releaseAndNotify(this); */
     }	//this will update subscribers. pointers haven't actually changed. 
}


